#include "GPUParam.h"

namespace egg{

    GPUParam::GPUParam(){
        mName="";
        mSize=0;
    }

    GPUParam::GPUParam(GLenum _type,const string& _name){
        mName=_name;
        switch(_type){
        case GL_FLOAT_VEC4:
            mType=GPT_Vec4;
            mSize=sizeof(vec4);
            break;
        case GL_FLOAT_MAT4:
            mType=GPT_Mat4;
            mSize=sizeof(mat4);
            break;
        case GL_FLOAT:
            mType=GPT_Float;
            mSize=sizeof(float);
            break;
        case GL_FLOAT_VEC3:
            mType=GPT_Vec3;
            mSize=sizeof(vec3);
            break;
        case GL_FLOAT_VEC2:
            mType=GPT_Vec2;
            mSize=sizeof(vec2);
            break;
        case GL_FLOAT_MAT3:
            mType=GPT_Mat3;
            mSize=sizeof(mat3);
            break;
        case GL_FLOAT_MAT2:
            mType=GPT_Mat2;
            mSize=sizeof(mat2);
            break;
        case GL_INT:
            mType=GPT_Int;
            mSize=sizeof(int);
            break;
        case GL_SAMPLER_2D:
        case GL_SAMPLER_CUBE:
            mType=GPT_Texture;
            mSize=sizeof(int);
            break;
        default:
            LogMgr->logMessage("shader param type error");
        }
    }

    GPUParam::GPUParam(GPUParamType _type,const string& _name){
        mName=_name;
        mType=_type;
        switch(mType){
        case GPT_Vec4:
            mSize=sizeof(vec4);
            break;
        case GPT_Mat4:
            mSize=sizeof(mat4);
            break;
        case GPT_Float:
            mSize=sizeof(float);
            break;
        case GPT_Vec3:
            mSize=sizeof(vec3);
            break;
        case GPT_Vec2:
            mSize=sizeof(vec2);
            break;
        case GPT_Mat3:
            mSize=sizeof(mat3);
            break;
        case GPT_Mat2:
            mSize=sizeof(mat2);
            break;
        case GPT_Int:
            mSize=sizeof(int);
            break;
        case GPT_Texture:
            mSize=sizeof(int);
            break;
        default:
            mSize=0;
            LogMgr->logMessage("shader param type error");
            break;
        }
    }

    NumericParam::NumericParam(const GPUParam& _other){
        mType=_other.getType();
        mName=_other.getName();
        mSize=_other.getSize();
        mData=new byte[mSize];
        memset(mData,0,mSize);
    }

    NumericParam::NumericParam(GPUParamType _type,const string& _name):GPUParam(_type,_name){
        mData=new byte[mSize];
        memset(mData,0,mSize);
    }

    TextureParam::TextureParam(const GPUParam& _other){
        mType=_other.getType();
        mName=_other.getName();
        mSize=_other.getSize();
        mSWrap=GL_REPEAT;
        mTWrap=GL_REPEAT;
    }

    TextureParam::TextureParam(const string& name):GPUParam(GPT_Texture,name){
        mSWrap=GL_REPEAT;
        mTWrap=GL_REPEAT;
    }

}